<!DOCTYPE html>
<html lang="en">
<head>
    {{/*网站配置*/}}
    {{template "header.tpl" .}}
</head>
<body>
<section class="content">
    <div class="layui-tab layui-tab-brief" style="width: 665px;">
        <ul class="layui-tab-title">
            {{range $key,$val := .configList}}
            <li {{if eq $key $.configId}} class="layui-this" {{end}}><a href="/system/webConfig/index?configId={{$key}}">{{$val}}</a>
            </li>
            {{end}}
        </ul>
        <div class="layui-tab-content">
            <form class="layui-form model-form" action="/system/webConfig/index">
                <input name="group_id" type="hidden" value="{{.configId}}">
                {{range $key,$val := .itemList}}
                {{if eq $val.type "hidden"}}
                <!-- 隐藏域 -->
                <input name="{{$val.code}}" id="{{$val.code}}" type="hidden" value="{{$val.value}}">
                {{else}}
                <div class="layui-form-item">
                    <label class="layui-form-label">{{$val.title}}：</label>
                    {{if eq $val.type "text"}}
                    <!-- 单行文本 -->
                    <div class="layui-input-block">
                        <input name="{{$val.code}}" value="{{$val.value}}" lay-verify="required" autocomplete="off"
                               placeholder="请输入{{$val.title}}" class="layui-input" type="text">
                    </div>
                    {{else if eq $val.type "number"}}
                    <!-- 数字文本 -->
                    <div class="layui-input-block">
                        <input name="{{$val.code}}" value="{{$val.value}}" lay-verify="required|number"
                               autocomplete="off" placeholder="请输入{{$val.title}}" class="layui-input" type="text">
                    </div>
                    {{else if eq $val.type "textarea"}}
                    <!-- 多行文本 -->
                    <div class="layui-input-block">
                        <textarea name="{{$val.code}}" placeholder="请输入{{$val.title}}" class="layui-textarea">{{$val.value}}</textarea>
                    </div>
                    {{else if eq $val.type "password"}}
                    <div class="layui-input-block">
                        <!-- 密码 -->
                        <input name="{{$val.code}}" value="{{$val.value}}" placeholder="请输入{{$val.title}}"
                               autocomplete="off" class="layui-input" type="password">
                    </div>
                    {{else if eq $val.type "radio"}}
                    <!-- 单选框 -->
                    <div class="layui-input-block">
                        {{range $key,$v := $val.optionsList}}
                        <input type="radio" name="{{$val.code}}" value="{{$key}}" title="{{$v}}"  {{ if eq $key $val.value}}checked{{end}}>
                        {{end}}
                    </div>
                    {{else if eq $val.type "checkbox"}}
                    <!-- 复选框 -->
                    <div class="layui-input-block">
                        {{/*{{checkbox (printf "%s__checkbox|name|id" $val.code) $val.optionsList $val.value}}*/}}
                        {{range $key,$v := $val.optionsList}}
                            <input name="{{$val.code}}" lay-skin="primary" title="{{$v}}"
                                    {{range $index,$sv := $val.value}}
                                        {{ if eq $sv $key}} checked="checked" {{end}}
                                    {{end}}
                                   type="checkbox">
                        {{end}}
                    </div>
                    {{else if eq $val.type "select"}}
                    <!-- 下拉框 -->
                    <div class="layui-input-block">
                        {{/*{{select (printf "%s|1|%s|name|id" $val.code $val.title) $val.optionsList $val.value}}*/}}
                        <label>
                            <select name="{{$val.code}}" class="form-control">
                            {{range $key,$v := $val.optionsList}}
                                <option value="{{$key}}">{{$v}}</option>
                            {{end}}
                            </select>
                        </label>
                    </div>
                    {{else if eq $val.type "date"}}
                    <!-- 日期 -->
                    <div class="layui-input-block">
                       {{/* {{date (printf "%s|1|结束时间|date" $val.code) $val.value}}*/}}
                    </div>
                    {{else if eq $val.type "datetime"}}
                    <!-- 时间 -->
                    <div class="layui-input-block">
                        {{/*{{date (printf "%s|1|结束时间|datetime" $val.code) $val.value}}*/}}
                    </div>
                    {{else if eq $val.type "image"}}
                    <!-- 单图 -->
                    {{/*{{upload_image (printf "%s__upimage|头像|90x90|建议上传尺寸450x450" $val.code) $val.value "" 0}}*/}}
                    {{upload_image}}
                    {{else if eq $val.type "images"}}
                    <!-- 多图 -->
                    <div class="layui-input-block">
                        {{/*{{album (printf "%s__upimgs|图集|90x90|20|建议上传尺寸450x450" $val.code) $val.value "" 0}}*/}}
                    </div>
                    {{else if eq $val.type "file"}}
                    <!-- 单文件上传 -->
                    {{else if eq $val.type "files"}}
                    <!-- 多文件上传 -->
                    {{else if eq $val.type "ueditor"}}
                    <!-- 富文本编辑器 -->
                    <div class="layui-input-block" style="width:665px;">
                        <textarea name="{{$val.code}}__ueditor" id="{{$val.code}}__ueditor" lay-verify="required"
                                  class="layui-textarea">{{$val.value}}</textarea>
                        {{/*{{kindeditor (printf "%s__ueditor" $val.code) "default" "80%" 350}}*/}}
                    </div>
                    {{else if eq $val.type "json"}}
                    <!-- JSON -->
                    {{end}}
                </div>
                {{end}}
                {{end}}
                {{/*{{submit "submit|立即保存,close|关闭" 1 "submitForm2"}}*/}}
                <div style="position: absolute;left: 15px;">
                    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="submitForm2"
                            lay-submit><i class="layui-icon layui-icon-ok"></i>立即保存
                    </button>
                    <button class="pear-btn pear-btn-sm" type="reset"><i class="layui-icon layui-icon-refresh"></i>重置
                    </button>
                </div>
            </form>
        </div>
    </div>
</section>
{{template "footer.tpl" .}}
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(dict-type-save)', function (data) {
            $.ajax({
                url: '/system/config/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("config-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

        /**
         * 提交表单
         */
        form.on('submit(submitForm2)', function (data) {
            // 网络请求
            var loadIndex = layer.load(2);
            $.ajax({
                type: "POST",
                url: '/system/webConfig/index',
                data: JSON.stringify(data.field),
                contentType: "application/json",
                dataType: "json",
                beforeSend: function () {
                    // TODO...
                },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.status === 200) {
                        //0.5秒后关闭
                        layer.msg(res.msg, {icon: 1, time: 500});
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                },
                error: function () {
                    layer.msg("AJAX请求异常");
                }
            });
            return false;
        });
    })

</script>
</body>
</html>